Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
13 | describe('Manager', function() { |
||
14 | before( function(done) { |
||
15 | Manager.instance.init() |
||
16 | .then(function () { |
||
17 | |||
18 | this.fixture = { |
||
19 | tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'), |
||
20 | jsonArticle: fse.readJsonSync(__dirname + '/fixtures/files/article-4.json'), |
||
21 | jsonArticle1: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json') |
||
22 | } |
||
23 | done() |
||
24 | |||
25 | }.bind(this)) |
||
26 | }); |
||
27 | |||
28 | it('getStructureAndTemplates()', function() { |
||
29 | const data = Manager.instance.getStructureAndTemplates() |
||
30 | chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') |
||
31 | chai.assert.equal(data['templates'].length, 7, 'failed !') |
||
32 | }); |
||
33 | |||
34 | it('updateStructureAndTemplates()', function() { |
||
35 | Manager.instance.updateStructureAndTemplates() |
||
36 | const data = Manager.instance.getStructureAndTemplates() |
||
37 | chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') |
||
38 | chai.assert.equal(data['templates'].length, 7, 'failed !') |
||
39 | }); |
||
40 | |||
41 | it('getList()', function() { |
||
42 | const list = Manager.instance.getList() |
||
43 | chai.assert.equal(list[0].name, 'article-1.json', 'failed !') |
||
44 | chai.assert.equal(list.length, 3, 'failed !') |
||
45 | }); |
||
46 | |||
47 | it('getListWithStatusOnFolder() status publish', function() { |
||
48 | const list = Manager.instance.getListWithStatusOnFolder('publish') |
||
49 | chai.assert.equal(list[0].name, 'article-1.json', 'failed !') |
||
50 | chai.assert.equal(list.length, 2, 'failed !') |
||
51 | }); |
||
52 | |||
53 | it('getListWithStatusOnFolder() status draft', function() { |
||
54 | const list = Manager.instance.getListWithStatusOnFolder('draft') |
||
55 | chai.assert.equal(list.length, 2, 'failed !') |
||
56 | }); |
||
57 | |||
58 | it('getListWithStatusOnFolder() status review', function() { |
||
59 | const list = Manager.instance.getListWithStatusOnFolder('review') |
||
60 | chai.assert.equal(list.length, 0, 'failed !') |
||
61 | }); |
||
62 | |||
63 | it('getListWithStatusOnFolder() status publish /0-1', function() { |
||
64 | const list = Manager.instance.getListWithStatusOnFolder('draft', '0-1') |
||
65 | chai.assert.equal(list[0].name, 'article-2.json', 'failed !') |
||
66 | chai.assert.equal(list.length, 1, 'failed !') |
||
67 | }); |
||
68 | |||
69 | it('updatePostInList() with new post', function(done) { |
||
70 | const len = Manager.instance.getList().length |
||
71 | cmsOperations.create('article', '', 'article-4.html', {query: ''}, this.fixture.jsonArticle, false) |
||
72 | .then(function(resSave) { |
||
73 | const json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
||
74 | const list = Manager.instance.getList() |
||
75 | fse.removeSync(json) |
||
76 | chai.assert.equal(list.length, len + 1, 'failed !') |
||
77 | done() |
||
78 | }.bind(this)); |
||
79 | }); |
||
80 | }); |
||
81 |